import time

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.keys import Keys

from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Chrome(r"C:\Users\42082\Desktop\chromedriver-win64\chromedriver.exe")
driver.get("https://www.toutiao.com/?wid=1698910582204")
# 获取页面高度
scroll_height = driver.execute_script('return document.documentElement.scrollHeight;')
print(scroll_height)

# 获取当前滚动条位置
scroll_top = driver.execute_script('return document.documentElement.scrollTop || document.body.scrollTop || window.pageYOffset;')
print(scroll_top)

# 判断是否需要继续滚动
# if scroll_top < scroll_height:
#     print("需要继续滚动")
#     # 需要继续滚动
#     driver.execute_script('window.scrollTo(0, 500);')
#     pass
# else:
#     # 不需要继续滚动
#     pass
# 循环滚动直到页面底部
while(1):
    # scroll_top < scroll_height:
    # 设置滚动条位置为页面底部
    driver.execute_script('window.scrollTo(0, document.documentElement.scrollHeight);')

    # 等待页面加载
    time.sleep(1)

    # 获取当前滚动条位置
    scroll_top = driver.execute_script(
        'return document.documentElement.scrollTop || document.body.scrollTop || window.pageYOffset;')



# wait=WebDriverWait(driver,10)
# wait.until(EC.presence_of_element_located((By.ID, "s_lg_img")))

#
# elements = driver.find_elements(By.XPATH,"//*[@id='root']/div/div[5]/div[1]/div/div/div/div[2]/div[6]")
# print(elements)

# for i in  elements:
#
#     print(i.text)

driver.close()


